package com.wss.lsl.alading.typehandler;

import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

public class DecimalToIntegerTypeHandler implements TypeHandler<BigDecimal> {

	@Override
	public void setParameter(PreparedStatement ps, int i, BigDecimal parameter,
			JdbcType jdbcType) throws SQLException {
		
		ps.setInt(i, parameter.intValue());
	}

	@Override
	public BigDecimal getResult(ResultSet rs, String columnName)
			throws SQLException {
		
		return new BigDecimal(rs.getInt(columnName));
	}

	@Override
	public BigDecimal getResult(ResultSet rs, int columnIndex)
			throws SQLException {
		
		return new BigDecimal(rs.getInt(columnIndex));
	}

	@Override
	public BigDecimal getResult(CallableStatement cs, int columnIndex)
			throws SQLException {
		
		return new BigDecimal(cs.getInt(columnIndex));
	}
	
}
